/**
 * Created by CP_hehongtao on 2017/9/15.
 */
/**
 * 获取URL拼参
 */
function getUrlParam(name, h) {
    var url = decodeURI(location.search); //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        var strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest[name];
};

/**
 * 获取默认头像
 * @param bridgeParam
 */
function getDefaultUserHead (userCode) {
    if(userCode){
        var defaultHeaderIndex = userCode % 8 + 1;
        return 'https://dl.app.gtja.com/pictures/niutou/tou' + defaultHeaderIndex + '@2x.png';
    }else{
        return './images/nrng/tou1@2x.png';
    }
};

/**
 * 四舍五入
 * @param number 需要处理的数字
 * @param digits 小数位数
 */
function toFixed(number, digits) {
    if (number === "") {
        return "";
    }
    if (isNaN(number)) {
        return number;
    }
    var object = new Number(number);
    var result = object.toFixed(digits);

    if (result == "-0.00") { // 解决部分负数保留两位小数后，-0.00，0.00 页面样式不一致问题，如 -0.0000012
        result = "0.00";
    }

    return result;
};

/**
 * 获取当前日期
 * yyyyMMdd
 */
function getTodayFormatDate() {
    var date = new Date();
    var seperator1 = "";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    return currentdate;
};

/**
 * 获取当前时分秒，补0
 * HHmmss
 */
function getTodayFormatTime() {
    var date = new Date();

    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();

    if (hour < 10) {
        hour = "0" + hour;
    }

    if (minute < 10) {
        minute = "0" + minute;
    }

    if (second < 10) {
        second = "0" + second;
    }

    var currentTime = hour + "" + minute + "" + second;
    return currentTime;
};

/**
 * 日期格式化
 * yyyyMMdd >> yyyy-MM-dd
 */
function formatDate(strDate) {
    strDate = strDate + "";
    if (!isNaN(strDate) && strDate.length == 8) {
        strDate = strDate.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1-$2-$3");
    }
    return strDate;
};

/**
 * 时间格式化
 * hhmmss >> hh:mm:ss
 */
function formatTime(time) {
    time = time + "";
    if(isNaN(time) || time.indexOf(".") > 0 || time<0){
        return time;
    }
    if (time.length == 5) {
        time = "0" + time;
    } else if (time.length == 4) {
        time = "00" + time;
    } else if (time.length == 3) {
        time = "000" + time;
    } else if (time.length == 2) {
        time = "0000" + time;
    } else if (time.length == 1) {
        time = "00000" + time;
    }
    if (time.length == 6) {
        time = time.replace(/^(\d{2})(\d{2})(\d{2})$/, "$1:$2:$3");
    }
    return time;
};